<?php


namespace App\Services\Jobposition;

use App\Exceptions\ApiExceptions;
use App\Models\JobpositionStatisticsModel;
use App\Models\JobpositionUvLogModel;
use App\Models\MessageModel;
use App\Models\User;
use App\Services\AbstractBaseService;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Facades\DB;

class MessageService extends AbstractBaseService
{
    /**
     * 增加聊天内容
     * @param int $userId
     * @param int $job_position_id
     * @param string $content
     * @return void
     * @throws ApiExceptions
     */
    public function storage(int $userId,int $job_position_id,string $content)
    {
        $res = MessageModel::query()->create([
            'user_id' => $userId,
            'job_position_id' => $job_position_id,
            'content' => $content,
        ]);
        if (!$res){
            throw new ApiExceptions('发送失败');
        }
    }

    /**
     * 客服聊天内容
     * @param int $userId
     * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
     */
    public function customerServiceMessage(int $userId)
    {
        return  MessageModel::query()->where(  'user_id' , $userId)
            ->where('job_position_id',-1)
            ->select(['content'])
            ->get();

    }
}